params=struct();
params.theta=1;
params.f=@(theta,x)(x+x^2*sin(theta*x));
params.g=-5;
params.y0=@(t)(sin(t));
params.y0d=@(t)(cos(t));
params.c=1;
params.gammax=1;
params.sigma=0.1;
params.epsilon=@(t)exp(-0.4*t);
params.phi=@(x)(x^2+5/4);

initial=[1;0;0];
[dxdt,s0]=rhs(0,initial,params);

opt=odeset("OutputFcn","odeplot");
[t,x]=ode45(@(t,x)rhs(t,x,params),[0 100],initial,opt);
s=repmat(s0,length(t),1);
y0=params.y0(t);
for i=1:length(t)
    [~,si]=rhs(t(i),x(i,:)',params);
    s(i)=si;
end

figure()
tiledlayout(4,1);
nexttile
N=@(chi)(exp(chi.^2).*cos(pi/2*chi));
X=linspace(-8,8,100);
Y=N(X);
YL=min(max(Y),-min(Y));
plot(X,Y)
ylim([-YL,YL])
title("$N(\chi)=e^{\chi^2}*\cos(\pi/2*\chi)$","Interpreter","latex")
grid on;
nexttile 
title("tracking")
hold on;
plot(t,y0,"DisplayName","y_d")
plot(t,x(:,1),"DisplayName","x")
legend();
xlim([0,4])
grid on;
nexttile
title("controller states")
hold on;
plot(t,x(:,2),"DisplayName","chi")
plot(t,x(:,3),"DisplayName","$\hat\theta$")
legend("interpreter","latex");
xlim([0,4])
grid on;
nexttile
title("control input")
hold on;
plot(t,horzcat(s.u),"DisplayName","u")
plot(t,horzcat(s.N),"DisplayName","N(\chi)")
legend();
xlim([0,4])
grid on;
